package main

import (
	"math/rand"
	"time"
)

type addRedPacketData struct {
	OpenId string `json:"uniqueid"`
	Level  int    `json:"level"`
	Time   int    `json:"time"`
	Sign   string `json:"sign"`
}

type getRedPacketData struct {
	OpenId string `json:"uniqueid"`
}

type addRedPacketReD struct {
	RedCode string `json:"red_code"`
}

type tempPacket struct {
	RedCode string `json:"red_code"`
	Type    int    `json:"type"`
	Amount  int    `json:"amount"`
	HeadImg string `json:"head_img"`
	Name    string `json:"name"`
	Level   int    `json:"level"`
}

type getRedPacketDataRe struct {
	List  interface{} `json:"list"`
	Money int         `json:"money"`
}

type helpRedPacketData struct {
	OpenId  string `json:"uniqueid"`
	RedCode string `json:"red_code"`
	Time    int    `json:"time"`
	Sign    string `json:"sign"`
}

type insertRedPacketData struct {
	RedCode string `json:"red_code"`
}

type drawRedPacketData struct {
	OpenId string `json:"uniqueid"`
}

type drawRedPacketResponse struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

type inviteRedReturn struct {
	Self    int    `json:"self"`
	Friend  int    `json:"friend"`
	RedCode string `json:"red_code"`
	HeadImg string `json:"head_img"`
	Name    string `json:"name"`
}

func randMoney(isNew int) int {
	var min, max, rands int64
	// 新用户40~60 老用户4~6
	if isNew == 0 { // 老用户
		min = 4
		max = 6
	} else if isNew == 1 { // 新用户
		min = 40
		max = 60
	} else { // 好友
		min = 8
		max = 10
	}

	for {
		rands = randInt64(min, max)
		if rands >= min && rands <= max {
			break
		}
	}
	return int(rands)
}

func randCard(isNew int) int {
	var min, max, rands int64
	// 新用户80~120 老用户8~12
	if isNew == 0 { // 老用户
		min = 8
		max = 12
	} else if isNew == 1 { // 新用户
		min = 80
		max = 120
	}

	for {
		rands = randInt64(min, max)
		if rands >= min && rands <= max {
			break
		}
	}
	return int(rands)
}

func randInt64(min, max int64) int64 {
	rand.Seed(time.Now().UnixNano())
	return min + rand.Int63n(max-min+1)
}
